import { uniAdminCacheKey } from '../constants.js'

export default {
    namespaced: true,
    state: {
        inited: false,
        navMenu: [],
        routes: [],
        theme: uni.getStorageSync(uniAdminCacheKey.theme) || 'default',
        appName: process.env.UNI_APP_NAME || '',
        appid: process.env.UNI_APP_ID || ''
    },
    mutations: {
        SET_APP_NAME: (state, appName) => {
            state.appName = appName
        },
        SET_NAV_MENU: (state, navMenu) => {
            state.inited = true
            state.navMenu = navMenu
        },
        SET_ROUTES: (state, routes) => {
            state.routes = routes
        },
        SET_THEME: (state, theme) => {
            document
                .getElementsByTagName('body')[0]
                .setAttribute('data-theme', theme)
            uni.setStorageSync(uniAdminCacheKey.theme, theme)
            state.theme = theme
        }
    },
    actions: {
        init({
            commit,
            dispatch
        })
        {
        //     // 初始化获取用户信息
        //     dispatch('user/getUserInfo', null, {
        //         root: true
        //     })
        }
        ,
        setAppName({
            commit
        }, appName) {
            commit('SET_APP_NAME', appName)
        },
        setRoutes({
            commit
        }, routes) {
            commit('SET_ROUTES', routes)
        }
    }
}
